//
//  RepairHistoryListCell.m
//  wtshoppingcite
//
//  Created by Baojia-LC on 14/11/13.
//  Copyright (c) 2014年 TW. All rights reserved.
//

#import "RepairHistoryListCell.h"
#import "UIImageView+WebCache.h"
@implementation RepairHistoryListCell

- (void)awakeFromNib {
    // Initialization code
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = COLOR_RGB(240, 240, 240);
        [self createSubViews];
    }
    return self;
}

-(void)createSubViews{
    
    _timeStapView = [[TimeStapView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40)];
    [_timeStapView initTimeTitleName:@[@"待受理",@"处理中",@"已完成"] step:0];
    [self.contentView addSubview:_timeStapView];
    
    _foodImageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, _timeStapView.bottom +5, 50, 50)];
    _foodImageView.contentMode = UIViewContentModeScaleAspectFill;
    _foodImageView.backgroundColor = MAIN_GRAY_COLOR;
    [self.contentView addSubview:_foodImageView];
    
    _titleLabel = [self createLabelWithFrame:CGRectMake(_foodImageView.right+10, _foodImageView.top +10, 200 , 20) text:@"" font:16 textAli:NSTextAlignmentLeft textColor:MAIN_GRAY_COLOR];
    [self.contentView addSubview:_titleLabel];
    
    _timeLabel = [self createLabelWithFrame:CGRectMake(_titleLabel.left, _titleLabel.bottom+5, 250, 20) text:@"" font:14 textAli:NSTextAlignmentLeft textColor:MAIN_GRAY_COLOR];
    [self.contentView addSubview:_timeLabel];
    
}

-(void)setRepairModel:(RepairModel *)repairModel{
    
    if(_repairModel != repairModel){
        _repairModel = repairModel;
//        NSString* title = ObjToString([data objectForKey:@"title"]);
//        NSString* status = ObjToString([data objectForKey:@"status"]);
//        NSString* image = ObjToString([data objectForKey:@"image"]);
//        NSString* time = ObjToString([data objectForKey:@"time"]);
        
        _titleLabel.text = repairModel.repairName;
        [_foodImageView setImageWithURL:[NSURL URLWithString:repairModel.smallImgPath]];
        _timeLabel.text = repairModel.createTime;
        [_timeStapView setStepStatus:repairModel.state];
    }
}

-(void)setComplaintModel:(ComplaintModel *)complaintModel{
    
    if(_complaintModel != complaintModel){
        _complaintModel = complaintModel;
        //        NSString* title = ObjToString([data objectForKey:@"title"]);
        //        NSString* status = ObjToString([data objectForKey:@"status"]);
        //        NSString* image = ObjToString([data objectForKey:@"image"]);
        //        NSString* time = ObjToString([data objectForKey:@"time"]);
        
        _titleLabel.text = complaintModel.title;
        [_foodImageView setImageWithURL:[NSURL URLWithString:complaintModel.smallImgPath]];
        _timeLabel.text = complaintModel.createTime;
        [_timeStapView setStepStatus:complaintModel.state];
    }
}

-(UILabel*)createLabelWithFrame:(CGRect)frame text:(NSString*)text font:(int)font textAli:(NSTextAlignment)alig textColor:(UIColor*)tc{
    if(text == nil)
        text = @"";
    UILabel* label = [[UILabel alloc] initWithFrame:frame];
    label.text = text;
    label.font = [UIFont systemFontOfSize:font];
    label.textAlignment = alig;
    label.textColor = tc;
    label.backgroundColor = [UIColor clearColor];
    return label;
}

@end
